<?php

namespace app\admin\controller\report;

use app\common\controller\Backend;

/**
 * 报表类目管理
 *
 * @icon fa fa-users
 */
class Category extends Backend
{

    /**
     * @var \app\admin\model\ReportCategory
     */
    protected $model = null;

    public function _initialize()
    {
        parent::_initialize();
        $this->model = model('ReportCategory');
        $this->view->assign("statusList", $this->model->getStatusList());
    }

    public function add()
    {
        if ($this->request->isPost()) {
            $this->token();
        }
        return parent::add();
    }

    public function edit($ids = null)
    {
        if ($this->request->isPost()) {
            $this->token();
        }
        $row = $this->model->get($ids);
        if (!$row) {
            $this->error(__('No Results were found'));
        }
        return parent::edit($ids);
    }

	public function source()
	{
		$json = cache('report_category');
		if ($json===false){
			$list = $this->model->where('status', 1)->column('id,name');
			$json = json($list);
			cache('report_category',$json);
		}
		return $json;
	}
}
